A tween glides a number from one value to another over a number of frames - a menu sliding in, a door opening, a bar filling. Start here - it says which of the two ways to make one to use (to make something move, it is tween_to), lists all sixteen curves, and says what happens to a glide when its instance is destroyed.
Setting x = 200 puts something at 200 in one frame. A tween is the number getting there over time: it starts where it is and arrives at 200 after, say, a second. How it travels is the curve: steady, speeding up, or braking at the end.
Want something to move? Use tween_to (it glides a variable from where it is now) or tween_from_to (it sets the start for you first). Both begin right now and run by themselves. tween is the other way: it only works out a number for you to use yourself.
So there are two ways to make one, and they suit different jobs.
tween | tween_to | |
|---|---|---|
| What it is | A number you read. | A glide the engine runs for you. |
| Where it lives | Nowhere. It is worked out from the frame counter each time. | In the engine, until it arrives. |
| You write | y = tween(0, 80, start, 120, EASE_QUAD_OUT); every frame. | tween_to(y, 80, 120, EASE_QUAD_OUT); once. |
| Good for | A value you draw or compare, like a bar or a fade. | Moving an instance or changing one of its variables. |
| In a pause | Keeps counting. | Waits. |
Write the name of the variable, where it should end up, how many frames it takes and the curve:
tween_to(x, x + 64, 60, EASE_QUAD_OUT);The walker's x glides 64 pixels to the right over one second, fast at first and braking as it arrives. Nothing else is needed: every frame the engine moves it a little further, and when it arrives it stops.
It works on any variable of an instance that holds a number: the built-in ones (x, y, angle, xscale...) and the ones you made yourself (hp, glow...). Name another instance's variable the same way you would read it:
var boss = instance_nearest(x, y, obj_doc_boss);
if (boss != nothing) {
tween_to(boss.hp, 0, 120, EASE_LINEAR);
}The boss's hp runs down to 0 over two seconds. A whole-number variable gets the nearest whole number on every step. A local variable or a global cannot be tweened, because they do not belong to an instance; the checker says so. In a script, x and the other built-in variables are the caller's, so tween_to(x, 100, 30, EASE_LINEAR) moves whoever called the script.
tween_from_to sets the start for you instead of using where the variable is now. tween_stop stops a glide where it has got to. tween_running says whether one is still going, so a move can wait for the one before it:
if (!tween_running(x)) {
if (x < xstart + 1) { tween_to(x, xstart + 64, 60, EASE_SINE_IN_OUT); }
else { tween_to(x, xstart, 60, EASE_SINE_IN_OUT); }
}Starting a tween on a variable that already has one replaces it: the new glide starts from where the variable is now, and the two never fight over the value.
Every tween call asks for a curve, and these are the sixteen you can pick from. Each name is a constant you can click to read about it (they are also listed together under Constants in the Reference).
| Starts slowly, speeds up (in) | Starts fast, brakes (out) | Slow at both ends (in out) | |
|---|---|---|---|
| Steady | EASE_LINEAR | ||
| Gentle | EASE_SINE_IN | EASE_SINE_OUT | EASE_SINE_IN_OUT |
| Stronger | EASE_QUAD_IN | EASE_QUAD_OUT | EASE_QUAD_IN_OUT |
| Winds up, runs past (goes outside the range) | EASE_BACK_IN | EASE_BACK_OUT | EASE_BACK_IN_OUT |
| Bounces (stays inside the range) | EASE_BOUNCE_IN | EASE_BOUNCE_OUT | EASE_BOUNCE_IN_OUT |
| Springs (goes outside the range) | EASE_ELASTIC_IN | EASE_ELASTIC_OUT | EASE_ELASTIC_IN_OUT |
The tween page shows how far along each one is after a quarter, half and three quarters of the time, and what is left out (cubic and steeper, circ and expo).
The first seven curves always keep the number between where it starts and where it ends. Back and elastic do not. They go a little (back) or a lot (elastic) past the end, or behind the start, because that is what makes a move feel springy, and then they settle exactly on the end. That is wonderful for a position and a mistake for a number with limits: if you tween hp or a volume with one of them, it will go above full or below empty for a moment. Use sine, quad or bounce for those. A bounce is the third family and it is the safe one: it never leaves the range.
Here are the three families, side by side. In each picture a ball moves steadily to the right (that is only the time, so you can see the shape) and its height is the number: it starts at the dim line and ends on the green one. Look for the ball going past the green line.


The same tween three ways, one row for each of EASE_BACK_IN, EASE_BACK_OUT and EASE_BACK_IN_OUT. The ball's height is the number (like tween_to(y, ...) moving something down), and it drifts right at a steady speed only so that the shape can be seen. The dim line is where the number starts and the green line is where it ends: look for the ball going past the green line, or behind the dim one. Real pictures from a Game Boy Advance ROM, 4 frames apart, played at the speed of the console. A viewer that does not animate shows the first picture, the finished one.


The same tween three ways, one row for each of EASE_BOUNCE_IN, EASE_BOUNCE_OUT and EASE_BOUNCE_IN_OUT. The ball's height is the number (like tween_to(y, ...) moving something down), and it drifts right at a steady speed only so that the shape can be seen. The dim line is where the number starts and the green line is where it ends: the ball touches the green line but never goes below it. Real pictures from a Game Boy Advance ROM, 4 frames apart, played at the speed of the console. A viewer that does not animate shows the first picture, the finished one.


The same tween three ways, one row for each of EASE_ELASTIC_IN, EASE_ELASTIC_OUT and EASE_ELASTIC_IN_OUT. The ball's height is the number (like tween_to(y, ...) moving something down), and it drifts right at a steady speed only so that the shape can be seen. The dim line is where the number starts and the green line is where it ends: the ball goes a long way past the green line (and, for the in, behind the dim one). Real pictures from a Game Boy Advance ROM, 4 frames apart, played at the speed of the console. A viewer that does not animate shows the first picture, the finished one.
A glide only ever writes into the instance it was started on. If that instance is destroyed, the glide just ends. It does not write into the dead instance, and it does not write into a new instance that was created in the same place a moment later: a tween remembers exactly which instance it was started on, not just where it lived. The game goes on as if nothing happened.
When you change room, every instance that is not persistent is destroyed, so their glides end too. A persistent instance keeps gliding into the next room.
Only 16 glides can run at the same moment (tween_max) - unless you changed Tweens gliding at once under Engine limits in Project Settings, from 1 to 64 (the rest of this page says 16, the number every game starts with); tween_count says how many are running now. The debug overlay has a TWEENS row with the same two numbers and the most there have ever been. If all 16 are busy, a new tween_to cannot glide: the variable jumps straight to its end value and tween_to gives back false. The game carries on and the door still ends up open, it just pops instead of sliding.
A game that never calls tween_to and its friends has none of this in its ROM: no table, no per-frame work. The reading form tween costs only where it is called.
The curves cost something too, but only the ones you use. A game that starts its tweens with tween_to and tween_from_to and always writes the curve out (EASE_QUAD_OUT) is built with just those curves. A curve held in a variable, or handed to a script, is one the game cannot know about in advance, so then it carries all sixteen. The reading form works out its curve where you call it and is not part of this.